package com.moses.transformer;

import com.moses.tools.ClassByteTool;

import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.security.ProtectionDomain;

public class FooTransformer implements ClassFileTransformer {


    @Override
    public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {

        if (!className.endsWith("com/moses/beans/Foo")) {
            return null;
        }

        String name = className.replaceAll("/", ".");
        byte[] bytes = ClassByteTool.addHint(name, "sayHello");
        if (bytes != null && bytes.length > 0) {
            return bytes;
        }
        return null;
    }
}
